<template>
	<view class="mainPage visit" :style="{'padding-top': `${$store.state.safeArea.top || 0}px`, 'padding-bottom': `${$store.state.safeArea.bottom || 0}px`}">
		<public-head :title="title"></public-head>
		<!--  -->
		<view class="visits" v-if="informations.hospital_name">
			<view class="box">
				<view class="box_1">
					<view class="htitle">出诊医院</view>
					<view class="hname"> {{informations.hospital_name}}</view>
				</view>
				<view class="box_2">
					<view class="htitle">开启接诊</view>
					<view class="hname">
						<u-switch @change="change" active-color="#4CD964" v-model="checked"></u-switch>
					</view>
				</view>
			</view>
			<view class="box1">
				<view class="box1_1" @click="tosettime">
					<view class="htitle">出诊时间设置</view>
					<view class="hname">
						<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/icon/icon_enter_homepage.png">
						</image>
					</view>
				</view>
				<view class="box1_1" @click="tosetprice">
					<view class="htitle">出诊费设置</view>
					<view class="hname">
						<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/icon/icon_enter_homepage.png">
						</image>
					</view>
				</view>
				<view class="box1_1" @click="tosetpeople">
					<view class="htitle">预约人数设置</view>
					<view class="hname">
						<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng_doctor/icon/icon_enter_homepage.png">
						</image>
					</view>
				</view>
				<view class="box_2">
					<view class="htitle">开启自动排班</view>
					<view class="hname">
						<u-switch active-color="#4CD964" @change="changes" v-model="checkeds"></u-switch>
					</view>
				</view>
			</view>
			<view class="box2">
				<p>1.关闭出诊后，用户将无法再进行预约，已产生预约单将自动取消，请谨慎操作；</p>
				<p>2.当天出诊时间不可修改；</p>
				<p>3.开启自动排班后，系统每天将根据您的设置自动生成排班表</p>
			</view>
		</view>
		<!-- 空状态 -->
		<view v-else>
			<view class="kong">
				<image src="https://swl-1304532176.cos.ap-guangzhou.myqcloud.com/chongesheng/img/mine/site.png" mode="">
				</image>
				<text>请设置就职医院</text>
			</view>
			<view class="baochun">
				<button type="default" class="btn" @click="toset">设置就职医院</button>
			</view>
		</view>
	</view>
</template>
<script>
var that
import publicHead from "@/components/publicHead/publicHead.vue"
export default {
	components: {
		publicHead
	},
	data() {
		return {
			title: "出诊设置",
			checked: 0,
			checkeds: 0,
			informations: '',//预约信息
			timer: null
		}
	},
	onLoad() {
		that = this
	},
	onShow() {
		that.information()
	},
	methods: {
		//设置医院
		toset() {
			uni.navigateTo({
				url: '../archives/archives'
			})
		},
		// 获取预约信息


		information() {
			that.$postAjax1('YuYue_get_yuyue_config', {
			}, function (data) {
				that.informations = data.data.data
				that.checked = that.informations.status
				that.checkeds = that.informations.is_loop
				console.log(that.informations)
			})
		},
		// 是否开启接诊
		change(checked) {
			if (checked == true) {
				checked = 1
			} else if (checked == false) {
				checked = 0
			}
			that.$postAjax1('YuYue_set_yuyue', {
				type: 1,//是否开启接诊
				value: checked
			}, function (data) {
				console.log('添加成功')
			})
			this.timer = setTimeout(() => {
				// 这里添加您的逻辑	
				that.information()
			}, 1000)
			console.log(checked);
		},
		// 是否开启自动排班
		changes(checkeds) {
			if (checkeds == true) {
				checkeds = 1
			} else if (checkeds == false) {
				checkeds = 0
			}
			that.$postAjax1('YuYue_set_yuyue', {
				type: 4,//是否开启自动排班
				value: checkeds
			}, function (data) {
				console.log('添加成功')
			})
			this.timer = setTimeout(() => {
				// 这里添加您的逻辑	
				that.information()
			}, 1000)
			console.log(checked);
		},
		tosetprice() {
			uni.navigateTo({
				url: './setprice'
			})
		},
		tosetpeople() {
			uni.navigateTo({
				url: './setpeople'
			})
		},
		tosettime() {
			uni.navigateTo({
				url: './settime'
			})
		}
	}
}
</script>
<style scoped lang="scss">
.visit {
	background: #f4f4f4;
	height: 100vh;
	.visits {
		.box {
			padding: 30rpx 40rpx;
			background-color: #ffffff;
			.box_1 {
				overflow: hidden;
				border-bottom: 1px solid #f0f0f0;
				padding-bottom: 36rpx;
				.htitle {
					display: inline-block;
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #323232;
					line-height: 44rpx;
				}
				.hname {
					display: inline-block;
					float: right;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #323232;
					line-height: 40rpx;
				}
			}
			.box_2 {
				padding-top: 34rpx;
				overflow: hidden;
				.htitle {
					display: inline-block;
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #323232;
					line-height: 44rpx;
				}
				.hname {
					display: inline-block;
					float: right;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #323232;
					line-height: 40rpx;
				}
			}
		}
		.box1 {
			padding: 0rpx 40rpx;
			margin-top: 8rpx;
			background-color: #ffffff;
			.box1_1 {
				padding-top: 34rpx;
				overflow: hidden;
				border-bottom: 1px solid #f0f0f0;
				padding-bottom: 36rpx;
				.htitle {
					display: inline-block;
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #323232;
					line-height: 44rpx;
				}
				.hname {
					display: inline-block;
					float: right;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #323232;
					line-height: 40rpx;
					image {
						width: 12rpx;
						height: 20rpx;
					}
				}
			}
			.box_2 {
				padding-top: 34rpx;
				overflow: hidden;
				padding-bottom: 34rpx;
				.htitle {
					display: inline-block;
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #323232;
					line-height: 44rpx;
				}
				.hname {
					display: inline-block;
					float: right;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #323232;
					line-height: 40rpx;
				}
			}
		}
		.box2 {
			padding: 30rpx 40rpx;
			p {
				font-size: 26rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #909090;
				line-height: 36rpx;
			}
		}
	}
	.kong {
		padding-top: 400rpx;
		text-align: center;
		image {
			margin: auto;
			display: block;
			width: 326rpx;
			height: 248rpx;
			margin-bottom: 30rpx;
		}
		text {
			font-size: 32rpx;
			font-weight: 400;
			color: #909090;
			line-height: 44rpx;
		}
	}
	.baochun {
		padding: 30rpx 60rpx 108rpx 60rpx;
		width: 100%;
		position: fixed;
		left: 0;
		background: #ffffff;
		bottom: 0;
		.btn {
			width: 100%;
			height: 92rpx;
			background: linear-gradient(270deg, #f78361 0%, #f54b64 100%);
			box-shadow: 0rpx 6rpx 8rpx 0rpx rgba(246, 80, 100, 0.2);
			border-radius: 46rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: #ffffff;
			line-height: 92rpx;
			text-align: center;
		}
	}
}
</style>
